package org.myproject.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.myproject.persistence.audit.DateCreated;
import org.myproject.persistence.audit.DateUpdated;

/**
 * <p>
 * User: Nick Heudecker
 * </p>
 * <p>
 * Date: Jan 27, 2008
 * </p>
 * <p>
 * Time: 5:35:03 PM
 * </p>
 */
@MappedSuperclass
public abstract class AbstractPersistent implements Serializable {

	@Id
	@GeneratedValue
	private Long id;

	@DateCreated
	@Column(updatable = false)
	private Date created;

	@Column(insertable = false)
	@DateUpdated
	private Date updated;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getCreated() {
		return created;
	}

	public Date getUpdated() {
		return updated;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		final AbstractPersistent other = (AbstractPersistent) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

}
